package com.potevio.simulator.task;


import com.potevio.simulator.common.GetHexMessage;
import com.potevio.simulator.config.MsgTypeConst;
import com.potevio.simulator.entity.SiginMsg0x10;
import com.potevio.simulator.heart.HeartbeatClient;
import io.netty.channel.Channel;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @ClassName Task
 * @Description:签到定时任务
 * @Date 2021/5/10  16:12
 * @Author zyd
 */
public class SiginMsgTask implements Runnable{
    private final static Logger LOGGER = LoggerFactory.getLogger(SiginMsgTask.class);

    public static Date LAST_START_TIME;
    private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private Channel channel;
    public SiginMsgTask(Channel channel) {
        this.channel = channel;
    }

    @SneakyThrows
    @Override
    public void run(){
        LOGGER.info("定时发送签到报文——msgLog");
//        System.out.println("channelId==============" + channel.id());
        Map<String, LinkedHashMap<String, String>> map = new GetHexMessage().getDataDomain(MsgTypeConst.SIGIN_MSG);
        // 最近一次启动时间
        map.get("0x10").put("lastStartTime", SIMPLE_DATE_FORMAT.format(LAST_START_TIME));
        map.get("0x10").put("chargingPile", SiginMsg0x10.chargingPile);
        channel.writeAndFlush(map);
    }
}
